#ifndef DEVICEITEMWIDGET_H
#define DEVICEITEMWIDGET_H

#include <QWidget>
#include <QLabel>
#include <QFrame>
#include <QColor>

class DeviceItemWidget : public QWidget
{
    Q_OBJECT
public:
    explicit DeviceItemWidget(const QString& name,
                              const QString& status,
                              const QString& idText,
                              const QColor& statusColor,
                              QWidget *parent = nullptr);

    ~DeviceItemWidget();  // ✅ 新增：析构函数，解除全局引用

    /* 外部接口 */
    void setActive(bool active);
    bool isActiveItem() const;

    void setName       (const QString& name);
    void setStatusText (const QString& status);
    void setDeviceId   (const QString& idText);
    void setStatusColor(const QColor& statusColor);  // 仅改圆点

signals:
    void clicked(DeviceItemWidget* self);

protected:
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event)      override;
    void mousePressEvent(QMouseEvent *event) override;

private:
    /* UI */
    QLabel *nameLabel   {};
    QLabel *statusLabel {};
    QLabel *statusDot   {};
    QLabel *idLabel     {};
    QFrame *leftLine    {};

    /* 状态 */
    bool   isHovered = false;
    bool   isActive  = false;
    QColor dotColor;

    void updateStyle();
};

#endif // DEVICEITEMWIDGET_H
